package com.relytosoft.mizar.media.camera.services.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.relytosoft.dubhe.common.core.object.ResponseResult;
import com.relytosoft.dubhe.common.log.annotation.OpLog;
import com.relytosoft.dubhe.common.log.enums.OpTypeEnum;
import com.relytosoft.mizar.media.camera.api.pojo.query.OfflineStartQuery;
import com.relytosoft.mizar.media.camera.api.pojo.query.OnlineStartQuery;
import com.relytosoft.mizar.media.camera.services.service.StreamService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author wss
 * @version 1.0
 * @date 2022/6/16 11:13
 */
@Api(tags = {"流控制器"})
@RestController
@RequestMapping("stream")
public class StreamController {

    @Resource(name = "offLineStreamServiceImpl")
    private StreamService offLineStreamService;
    @Resource(name = "onLineStreamServiceImpl")
    private StreamService onLineStreamService;

    @SaCheckPermission("online:start")
    @OpLog(msg = "实时录像开始", opType = OpTypeEnum.INSERT)
    @ApiOperation("实时录像开始")
    @PostMapping("/online/start")
    public ResponseResult<Integer> onLineStart(@RequestBody OnlineStartQuery onlineStartQuery) {
        Integer taskId = onLineStreamService.recordByFrame(OnlineStartQuery.buildDto(onlineStartQuery));
        return ResponseResult.ok(taskId);
    }

    @SaCheckPermission("online:stop")
    @OpLog(msg = "实时停止录像", opType = OpTypeEnum.OTHER)
    @ApiOperation("实时停止录像")
    @PostMapping("/stop/{taskId}")
    public ResponseResult<Void> onLineStop(@PathVariable Integer taskId) {
        StreamService.STOP_MAP.put(taskId, true);
        return ResponseResult.ok();
    }

    @SaCheckPermission("offLine:start")
    @OpLog(msg = "离线开始录像", opType = OpTypeEnum.INSERT)
    @ApiOperation("离线开始录像")
    @PostMapping("/offLine/start")
    public ResponseResult<Void> offLineStart(@RequestBody OfflineStartQuery offlineStartQuery) {
        offLineStreamService.recordByFrame(OfflineStartQuery.buildDto(offlineStartQuery));
        return ResponseResult.ok();
    }

}
